﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ClipperBaseUI.Controls;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace Clipper.ResultAndCurve
{
    /// <summary>
    /// WinHistoryCurve.xaml 的交互逻辑
    /// </summary>
    public partial class WinHistoryCurve : BaseWindow
    {
        public WinHistoryCurve()
        {
            InitializeComponent();
        }
        BLL.DetectItems mDetectItemBll = new BLL.DetectItems();
        BLL.StandardInfo mStandardInfoBll = new BLL.StandardInfo();

        private void BaseWindow_Loaded(object sender, RoutedEventArgs e)
        {
            ObservableCollection<Model.DetectItems> modelList = null;
            BackgroundWorker back = new BackgroundWorker();
            back.DoWork += (ss,ee) =>
                {
                    modelList = mDetectItemBll.GetSelectItemsList();
                };
            back.RunWorkerCompleted += (ss, ee) =>
                {
                    if (modelList != null)
                    {
                        cboDetectItem.ItemsSource = modelList;
                    }
                };
            back.RunWorkerAsync();
        }

        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            DateTime? dateStart, dateEnd;
            string detectItem = "";
            dateStart = dtpStart.SelectedDate;
            dateEnd = dtpEnd.SelectedDate;

            if (cboDetectItem.SelectedValue != null)
            {
                detectItem = cboDetectItem.SelectedValue.ToString();
            }
            else
            {
                UIHelper.ShowKeyMessage("SelectItemTip");
                return;
            }
            if (dateStart == null)
            {
                UIHelper.ShowKeyMessage("StartDateTip");
                return;
            }
            if (dateEnd == null)
            {
                UIHelper.ShowKeyMessage("EndDateTip");
                return;
            }
            lsbHistory.ItemsSource = mStandardInfoBll.GetHistory(detectItem, dateStart, dateEnd);
        }
        
    }
}
